//
//  GouWuCheView.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/9.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "GouWuCheView.h"

@implementation GouWuCheView

- (void)setCountNumStr:(NSString *)countNumStr {
    _countNumStr = countNumStr;
}
- (void)setPostMoneyStr:(NSString *)postMoneyStr {
    _postMoneyStr = postMoneyStr;
    
    
}
-(void)setCountMoneyStr:(NSString *)countMoneyStr {
    _countMoneyStr = countMoneyStr;
     [self configureView];
    
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = KShouYeBg;
        
    }
    return self;
}


- (void)configureView {
    
    
    if (_seleAllBtn ) {
        [_seleAllBtn removeFromSuperview];
    }
    if (_counBtn) {
        [_counBtn removeFromSuperview];
    }
    if (_deleBtn) {
        [_counBtn removeFromSuperview];
    }
    
    if (_allMoneyLabel) {
        [_allMoneyLabel removeFromSuperview];
    }
    if (_hejiLB) {
        [_hejiLB removeFromSuperview];
    }
    if (_postMoneyLabel) {
        [_postMoneyLabel removeFromSuperview];
    }
    
    //全选按钮
   _seleAllBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _seleAllBtn.frame = CGRectMake(10, 10, 80, 30);
    [_seleAllBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_seleAllBtn setTitleColor:KBtnColor  forState:(UIControlStateSelected)];
    
    [_seleAllBtn setTitle:@"全选" forState:(UIControlStateNormal)];
    [_seleAllBtn setImage:[UIImage imageNamed:@"gouwuche_quan"] forState:(UIControlStateNormal)];
    [_seleAllBtn setImage:[UIImage imageNamed:@"gouwuche_quan2"] forState:(UIControlStateSelected)];
    _seleAllBtn.imageEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0,10.0);

    [_seleAllBtn addTarget:self action:@selector(handleSelectAll:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:_seleAllBtn];
    
    
    
    
    
    
    
    
    
    
    
    
    
    //结算按钮
    _counBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _counBtn.frame = CGRectMake(kView_Width - 100, 0, 100, 50);
    [_counBtn setTitle:_countNumStr  forState:(UIControlStateNormal)];
    [_counBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_counBtn setBackgroundColor:[UIColor grayColor]];
    _counBtn.titleLabel.font = kFont15;
    [self addSubview:_counBtn];
    
    
    //删除按钮
    _deleBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [_deleBtn setBackgroundImage:[UIImage imageNamed:@"chengkuai"] forState:(UIControlStateNormal)];
    _deleBtn.frame = CGRectMake(CGRectGetMinX(_counBtn.frame)- CGRectGetWidth(_counBtn.frame), CGRectGetMinY(_counBtn.frame), CGRectGetWidth(_counBtn.frame), CGRectGetHeight(_counBtn.frame));
    [_deleBtn setTitle:@"删除" forState:(UIControlStateNormal)];
    _deleBtn.hidden = YES;
    _deleBtn.titleLabel.font = kFont15;
    [self addSubview:_deleBtn];
    
    
    
    //总钱数
    _allMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(_counBtn.frame)-30-10, 5, 30, 20)];
    _allMoneyLabel.font = [UIFont systemFontOfSize:16];
    _allMoneyLabel.textColor = [UIColor orangeColor];
    _allMoneyLabel.text= @"¥ 0";
    _allMoneyLabel.text = _countMoneyStr;
    CGFloat width = [self getWidthWithTitle:_allMoneyLabel.text font:_allMoneyLabel.font];
    _allMoneyLabel.frame = CGRectMake(CGRectGetMinX(_counBtn.frame)-width-10, 5, width, 20);
    _allMoneyLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_allMoneyLabel];
    
    //合集lb
    
    _hejiLB = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(_allMoneyLabel.frame)-50, 5, 50, 20)];
    _hejiLB.textColor = [UIColor blackColor];
    _hejiLB.text = @"合计:";
    _hejiLB.font = kFont17;
    [self addSubview:_hejiLB];
    
    
    _postMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(_counBtn.frame)-110, CGRectGetMaxY(_allMoneyLabel.frame), 100, 20)];
    _postMoneyLabel.text = @"(含运费20元)";
    _postMoneyLabel.font = kFont13;
    _postMoneyLabel.textAlignment = NSTextAlignmentRight;
    _postMoneyLabel.textColor = [UIColor grayColor];
    [self addSubview:_postMoneyLabel];
    
    
    
}

//按钮的隐藏和出现
- (void)hiddenOrPlayFlage:(BOOL )flage {
    _hejiLB.hidden = flage;
    _postMoneyLabel.hidden = flage;
    _allMoneyLabel.hidden = flage;
    _deleBtn.hidden = !flage;
}
#pragma mark 全选按钮的点击事件
- (void)handleSelectAll:(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(selectAllAction:)])
    {
        [self.delegate selectAllAction:sender];
    }
}


- (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = font;
    [label sizeToFit];
    return label.frame.size.width;
}








@end
